package com.app.view_controller.custom_view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ToggleButton;

@SuppressWarnings("unused")
public class CustomToggleButton extends ToggleButton {

	private static final String TAG = "CUSTOM TOGGLE";
	private static final boolean DEBUG = true;
	private CharSequence textOn;
	private CharSequence textOff;
	private String mText;
	private Paint mTextPaint;
	private float mtextSize;
	private Rect mTextBounds;

	public CustomToggleButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	private void init() {
		textOn = getTextOn();
		textOff = getTextOff();
		mText = (String) textOff;
		mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		mTextPaint.setColor(Color.BLACK);
		mTextPaint.setTextSize(getTextSize());
		mTextBounds = new Rect();
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		int minh = getPaddingTop()+getPaddingBottom()+getSuggestedMinimumHeight();
		int minw = getPaddingLeft() + getPaddingRight()+getSuggestedMinimumWidth();
		int h = resolveSize(minh, heightMeasureSpec);
		int w = resolveSizeAndState(minw, widthMeasureSpec,0);
		mTextPaint.getTextBounds(mText, 0, 3, mTextBounds);
		setMeasuredDimension(w, h);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		canvas.drawText(mText, (canvas.getWidth()-mTextBounds.width())/2, canvas.getHeight()/2, mTextPaint);
	}

}
